<template>
  <div class="policyBox">
    <div class="policyTitle">
      <!-- <div class="policyTypeName"
				 :style="'color: ' + formatLabel(policy.typeName).color + '; background-color: ' + formatLabel(policy.typeName).bgColor">
				{{formatLabel(policy.typeName).label}}
      </div>-->
      <div class="policyTypeName">{{ policy.typeName }}</div>
      <div class="policyPv">
        <!-- <img src="@/assets/image/policyList/eye.png" />
        <span style="margin-left: 5px">{{policy.pv}}</span>-->
      </div>
    </div>
    <div
      class="policyMsg"
      @click="
        $router.push({
          path: 'policyDetail',
          query: { id: policy.id, item: '1' },
        })
      "
    >
      <div
        style="
          display: flex;
          justify-content: space-between;
          align-items: center;
        "
      >
        <!-- <span
          class="policyDate"
        >{{policy.createTime.replaceAll('-', '/').substr(0, 10) + ' | ' + policy.radiationArea}}</span>-->
        <div class="policyDate">{{ policy.no }}</div>
        <!-- <span
          style="color: #D00000; font-size: 15px; white-space: nowrap"
        >{{policy.approachEnd == 1 && policy.status != 3 ? '即将到期' : ''}}</span>-->
      </div>
      <div class="policyName">{{ policy.name }}</div>
      <div class="policyDescriptionDiv">
        <div class="policyDescription">{{ policy.description }}</div>
      </div>
      <!-- <div class="policyUnit">{{'发文部门：' + policy.publishUnit}}</div> -->
      <div class="policyUnitquanbu">
        <div class="policyUnit">
          <div class="aprt">{{ "发文部门：" + policy.publishUnit }}</div>
          <!-- <div>{{'申报日期：' + policy.beginDate + '至' + policy.closingDate}}</div> -->
          <div>
            发文日期：{{
            policy.createTime?policy.createTime.replaceAll("-", "/").substr(0, 10):''
            }}
          </div>
        </div>
        <div class="policyUnit">
          <div>&nbsp;</div>
          <!-- <div>{{'发文日期：' + policy.createTime.replaceAll('-', '/').substr(0, 10)}}</div> -->
          <div>{{ "阅读浏览：" + policy.pv + "次" }}</div>
        </div>
      </div>
    </div>
    <div class="policyFooter">
      <div :style="'color: ' + formatStatus(policy.status).color">
        {{
        policy.status != null ? "·" + formatStatus(policy.status).label : ""
        }}
      </div>
      <div style="display: flex; align-items: center">
        <div
          class="policyApproachDay"
          v-if="policy.approachDay != null"
        >{{ "距开始还有" + policy.approachDay + "天" }}</div>
        <Buttons :buttons="buttons" @toPolicyDetail="toPolicyDetail(policy)" @none="''"></Buttons>
        <!-- <div
          class="policyBtn"
          :style="
            'color :' +
            formatBtn(policy).color +
            '; background-color :' +
            formatBtn(policy).bgColor
          "
          v-if="policy.applyStatus != 2"
          @click="toPolicyDetail(policy)"
        >立即申报</div>
        <div
          class="cantPolicyBtn"
          :style="
            'color :' +
            formatBtn(policy).color +
            '; background-color :' +
            formatBtn(policy).bgColor
          "
          v-if="policy.applyStatus == 2"
        >已申报</div> -->
      </div>
    </div>
  </div>
</template>

<script>
import common from '@/utils/common.js'
import { formatLabel, formatSendBtn } from '@/utils/util.js'

export default {
  name: 'policyFrame',
  data() {
    return {
      policyTypeColors: [
        {
          color: '#f09450',
          bgColor: '#F7F1EB',
        },
        {
          color: '#1abc9c',
          bgColor: '#e2f6f4',
        },
        {
          color: '#ff6c6a',
          bgColor: '#ffeef0',
        },
      ],
    }
  },
  props: {
    policy: {
      type: Object,
      default: {},
    },
    index: {
      type: Number,
    },
  },
  computed:{
    buttons(){
      if(this.policy.applyStatus != 2){
        if(this.policy.status == 3){
          return [{text:"立即申报",type:"gray",size:"l",method:"none"}]
        } else if(this.policy.status == 2){
          return [{text:"立即申报",type:"weakSuccess",size:"l",method:"none"}]
        } else {
          return [{text:"立即申报",type:"success",size:"l",method:"toPolicyDetail"}]
        }
      } else {
        return [{text:"已申报",type:"weakSuccess",size:"l",method:"none"}]
      }
    }
  },
  methods: {
    /**
     * 跳转到政策详情页面
     */
    toPolicyDetail: function (policy) {
      let ns = this
      if (!formatSendBtn(policy).canIn) {
        return
      }
      ns.$router.push({
        path: 'policyDetail',
        query: { id: policy.id },
      })
    },
    /**
     * 格式化标签
     * @param label 标签名
     * @return {string|*} 标签名对象
     */
    formatLabel: function (label) {
      return formatLabel(label)
    },
    /**
     * 格式化显示政策状态
     * @param status 政策状态
     * @return {string|*} 政策状态字符串
     */
    formatStatus: function (status) {
      if (status == null || status == undefined) {
        return { label: '' }
      }
      for (let i = 0; i < common.policyStatus.length; i++) {
        if (common.policyStatus[i].value == status) {
          return common.policyStatus[i]
        }
      }
      return { label: '' }
    },
    /**
     * 格式化显示按钮颜色
     */
    formatBtn: function (policy) {
      return formatSendBtn(policy)
    },
  },
}
</script>

<style scoped>
.policyBox {
  height: 350px;
  margin-bottom: 20px;
  border: 1px solid #e1e1e1;
  position: relative;
  transition: all 0.2s ease 0s;
}

.policyBox:hover {
  box-shadow: 0px 5px 5px #e1e1e1;
}

.policyBox .policyTitle {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}

.policyBox .policyTitle .policyTypeName {
  padding: 10px 20px;
  /* background-color: yellow; */
  background: #f4fbff;
  color: #5f89e6;
  font-size: 15px;
}

.policyBox .policyTitle .policyPv {
  display: flex;
  align-items: center;
  margin-right: 30px;
}

.policyBox .policyMsg {
  text-align: left;
  margin: 20px;
}

.policyBox .policyMsg:hover {
  cursor: pointer;
}

.policyBox .policyMsg .policyDate {
  font-size: 15px;
  color: #999999;
}

.policyBox .policyMsg .policyName {
  font-size: 25px;
  font-weight: bold;
  margin: 10px 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}

.policyBox .policyMsg:hover .policyName {
  color: #045db9;
}

.policyBox .policyMsg .policyDescriptionDiv {
  /* height: 30px; */
}

.policyBox .policyMsg .policyDescriptionDiv .policyDescription {
  font-size: 15px;
  height: 40px;
  color: #999999;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  line-height: 20px;
}
.policyUnitquanbu {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
}
.policyBox .policyMsg .policyUnit {
  font-size: 14px;
  /* margin-top: 40px; */
}
.policyBox .policyMsg .policyUnit .aprt {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 277px;
}
.policyBox .policyFooter {
  margin: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  bottom: 20px;
  width: calc(100% - 40px);
  border-top: 1px solid #eeeeee;
  padding-top: 20px;
}

.policyBox .policyFooter .policyApproachDay {
  font-size: 12px;
  color: #d00000;
  margin-right: 10px;
}

.policyBox .policyFooter .policyBtn {
  padding: 10px 0;
  background-color: #045db9;
  border-radius: 3px;
  font-size: 15px;
  color: #f1f2f4;
  width: 100px;
  transition: all 0.2s ease 0s;
}

.policyBox .policyFooter .policyBtn:hover {
  cursor: pointer;
}

.policyBox .policyFooter .cantPolicyBtn {
  padding: 10px 0;
  background-color: #f1f2f4;
  border-radius: 3px;
  font-size: 15px;
  color: #999999;
  width: 100px;
}

.policyBox .policyFooter .cantPolicyBtn:hover {
  cursor: pointer;
}
</style>
